from motor.motor_asyncio import AsyncIOMotorCollection
from elasticsearch import AsyncElasticsearch


class Mongo(object):
    clients = None

    def __getitem__(self, item):
        return self.clients[item]

    def get_collection(self, col_const: str) -> AsyncIOMotorCollection:
        client_name, db_name, col_name = col_const.split(".")
        client = self.clients[client_name]
        return client[db_name][col_name]

    @staticmethod
    def get_collection_name(col_const: str):
        client_name, _, _ = col_const.split(".")
        return client_name


class ElasticSearch(object):
    clients = None

    def __getitem__(self, item):
        return self.clients[item]

    def get_connect_info(self, index_const: str) -> (AsyncElasticsearch, str):
        client_name, index = index_const.split(".")
        client = self.clients[client_name]
        return client, index


mdb = Mongo()
es = ElasticSearch()